import request, { filterUsefulRequestParams } from '@/utils/request';

// 查询员工档案头部信息
export function queryEmployeeArchiveHead({ employeeCode, dutyCode }) {
    return request('/api/uc/employee/manage/v1/queryEmployeeArchiveHead', {
        method: 'GET',
        params: filterUsefulRequestParams({ employeeCode, dutyCode })
    });
}

// 查询员工的直接上级信息
export function queryImmediateSuperior({ employeeCode, dutyCode }) {
    return request('/api/uc/employee/manage/v1/queryImmediateSuperior', {
        method: 'GET',
        params: filterUsefulRequestParams({ employeeCode, dutyCode })
    });
}

// 查询直属下级数量
export function queryChargeNumber({ employeeCode, dutyCode }) {
    return request('/api/uc/employee/manage/v1/queryChargeNumber', {
        method: 'GET',
        params: filterUsefulRequestParams({ employeeCode, dutyCode })
    });
}

// 查询员工在职信息
export function queryEmployeeOnJobInfo({ employeeCode, dutyCode }) {
    return request('/api/uc/org/employee/v1/queryEmployeeOnJobInfo', {
        method: 'GET',
        params: filterUsefulRequestParams({ employeeCode, dutyCode })
    });
}

// 查询员工状态信息
export function queryEmployeeStatusInfoVO({ employeeCode }) {
    return request('/api/uc/org/employee/v1/queryEmployeeStatusInfoVO', {
        method: 'GET',
        params: { employeeCode }
    });
}

// 查询员工的岗位兼任信息列表
export function queryEmployeeDutyList({ employeeCode }) {
    return request('/api/uc/org/employee/v1/queryEmployeeDutyList', {
        method: 'GET',
        params: { employeeCode }
    });
}

// 获取个人信息
export function getPersonalDoc({ employeeCode }) {
    return request('/api/org/employee/manage/v1/employee/getPersonalDoc', {
        method: 'POST',
        data: { employeeCode }
    });
}

// 获取联系人信息
export function getContactDoc({ employeeCode }) {
    return request('/api/uc/employee/manage/v1/employee/getContactDoc', {
        method: 'POST',
        data: { employeeCode }
    });
}

// 获取用户基础信息
export async function saveEmployeeBasicInfo(param) {
    return request('/api/org/employee/manage/v1/employee/updateBasic', {
        data: param,
        method: 'POST'
    });
}

// 修改联系信息
export async function saveContactInfo(param) {
    return request('/api/org/employee/manage/v2/employee/updateContactInfo', {
        data: param,
        method: 'POST'
    });
}

// 修改紧急联系人
export async function saveEmployeeEmergencyData(param) {
    return request('/api/uc/employee/manage/v1/employee/updateEmergency', {
        data: param,
        method: 'POST'
    });
}

// 修改工作经历
export async function saveEmployeeWorkData(param) {
    return request('/api/uc/employee/manage/v1/employee/updateWork', {
        data: param,
        method: 'POST'
    });
}

// 修改教育经历
export async function saveEmployeeEducationalData(param) {
    return request('/api/uc/employee/manage/v1/employee/updateEdu', {
        data: param,
        method: 'POST'
    });
}

// 修改家庭成员
export async function saveEmployeeFamilyData(param) {
    return request('/api/uc/employee/manage/v1/employee/updateFamily', {
        data: param,
        method: 'POST'
    });
}

// 修改培训经历
export async function saveEmployeeTrainingData(param) {
    return request('/api/uc/employee/manage/v1/employee/updateTrain', {
        data: param,
        method: 'POST'
    });
}

// 修改获奖记录
export async function saveEmployeeAwardData(param) {
    return request('/api/uc/employee/manage/v1/employee/updateAward', {
        data: param,
        method: 'POST'
    });
}

// 更新语言信息
export function saveLanguages(params) {
    return request('/api/uc/employee/manage/v1/employee/updateLang', {
        method: 'POST',
        data: params
    });
}

// 更新技能信息
export function saveSkill(params) {
    return request('/api/uc/employee/manage/v1/employee/updateSkill', {
        method: 'POST',
        data: params
    });
}

/**
 * 查询员工入职材料
 */
export function queryEmployeeEntryResource({ employeeCode }) {
    return request(`/api/entry/employee/v2/queryEmployeeEntryResource/${employeeCode}`, {
        method: 'GET'
    });
}

/**
 * 获取员工实体材料
 */
export function getEmployeeEntityMaterial({ employeeCode }) {
    return request(`/api/entry/employee/v2/entityMaterial/${employeeCode}`, {
        method: 'GET'
    });
}

/**
 * 上传员工实体材料信息
 */
export function uploadEmployeeEntityMaterial({ employeeCode, materials }) {
    return request('/api/entry/employee/v2/selfEntityMaterial', {
        method: 'POST',
        data: { employeeCode, materials }
    });
}

/**
 * 删除员工实体材料信息
 */
export function removeEmployeeEntityMaterial({ employeeCode, categoryCode, keyName }) {
    return request('/api/entry/employee/v2/delSelfEntityMaterial', {
        method: 'DELETE',
        data: { employeeCode, categoryCode, keyName }
    });
}

// 最高学历
export function getDegreeList() {
    return Promise.resolve([
        {
            label: '博士及以上',
            value: '5'
        },
        {
            label: '硕士',
            value: '4'
        },
        {
            label: '本科',
            value: '3'
        },
        {
            label: '大专',
            value: '2'
        },
        {
            label: '高中',
            value: '1'
        },
        {
            label: '中专',
            value: '6'
        },
        {
            label: '初中及以下',
            value: '7'
        }
    ]);
}

// 查询员工历程列表
export function queryEmployeeCourseList({ employeeCode }) {
    return request('/api/org/v1/employeeInfo/queryEmployeeCourseList', {
        method: 'POST',
        data: { employeeCode }
    });
}

// 查询员工固定资产列表
export function getEmployeeAssetList({ employeeCode }) {
    return request('/api/uc/employee/manage/v1/getEmployeeAssetList', {
        method: 'GET',
        params: { employeeCode }
    });
}

// 查询员工虚拟资产信息
export function getEmployeeVirtualAsset({ employeeCode }) {
    return request('/api/uc/employee/manage/v1/getEmployeeVirtualAsset', {
        method: 'GET',
        params: { employeeCode }
    });
}

// 查询员工虚拟资产信息
export function getEmployeeOfficeStationInfo({ employeeCode }) {
    return request('/api/uc/employee/manage/v1/getEmployeeOfficeStationInfo', {
        method: 'GET',
        params: { employeeCode }
    });
}

// 查询员工工资信息
export function getEmployeeSalaryInfo({ employeeCode }) {
    return request('/api/org/employee/manage/v1/getEmployeeSalaryInfo', {
        method: 'GET',
        params: { employeeCode }
    });
}

// 查询员工工资卡信息
export function getEmployeeBankCardInfo({ employeeCode }) {
    return request('/api/org/employee/manage/v1/getEmployeeBankCardInfo', {
        method: 'GET',
        params: { employeeCode }
    });
}

// 保存员工工资卡信息
export function saveEmployeeBankCardInfo(params) {
    return request('/api/org/employee/manage/v2/employee/updateBankCard', {
        method: 'POST',
        data: params
    });
}

// 保存员工工资信息
export function saveEmployeeSalaryInfo(params) {
    return request('/api/org/employee/manage/v2/updateEmployeeSalaryInfo', {
        method: 'POST',
        data: params
    });
}

// 查询员工社保公积金信息
export function getEmployeeInsuranceAndProvidentInfo({ employeeCode }) {
    return request('/api/org/employee/manage/v1/getEmployeeInsuranceAndProvidentInfo', {
        method: 'GET',
        params: { employeeCode }
    });
}

// 保存员工社保公积金信息
export function saveEmployeeInsuranceAndProvidentInfo(params) {
    return request('/api/org/employee/manage/v2/employee/updateInsuranceProvident', {
        method: 'POST',
        data: params
    });
}

// 查询员工个税专项附加扣除信息
export function getPersonalTaxSpecialDeduction({ employeeCode }) {
    return request('/api/org/employee/manage/v2/getPersonalTaxSpecialDeduction', {
        method: 'GET',
        params: { employeeCode }
    });
}

// 保存员工个税专项附加扣除信息
export function savePersonalTaxSpecialDeduction(params) {
    return request('/api/org/employee/manage/v2/employee/updatePersonalTaxSpecialDeduction', {
        method: 'POST',
        data: params
    });
}

// 查询员工CPF信息
export function getCpf({ employeeCode }) {
    return request('/api/org/employee/manage/v2/getCpf', {
        method: 'GET',
        params: { employeeCode }
    });
}

// 编辑CPF信息
export function saveCpf(params) {
    return request('/api/org/employee/manage/v2/employee/updateCpf', {
        method: 'POST',
        data: params
    });
}

/**
 * 查询员工列表
 */
export function queryEmployeeListPage(params) {
    return request('/api/uc/employee/manage/v1/queryEmployeeListPage', {
        data: filterUsefulRequestParams(params),
        method: 'POST'
    });
}

/**
 * 导出员工列表
 */
export function downEmployeeList(params) {
    return request('/api/oa/v1/stream/employee/export/list', {
        method: 'POST',
        data: filterUsefulRequestParams(params),
        getResponse: true,
        encryption: false,
        isFile: true,
        responseType: 'blob',
        headers: { 'Content-Type': 'application/json' }
    });
}

/**
 * 员工列表统计信息
 */
export function queryEmployeeCountStatistical() {
    return request('/api/uc/employee/manage/v1/queryEmployeeCountStatistical', {
        method: 'GET'
    });
}
/**
 * 查询员工关怀记录
 * @param {string} careStarterCode 关怀发起人
 * @param {integer} careType 关怀类型
 * @param {string} caredEmployeeCode 被关怀员工
 * @param {string} currentEmployeeCode 当前登录人员工code
 * @returns {Promise<any|{data: {data: *}}|{data: *}>}
 */
export async function queryEmployeeCareList({ careStarterCode, careType, caredEmployeeCode, currentEmployeeCode }) {
    return request('/api/uc/employee/care/queryEmployeeCareList', {
        method: 'POST',
        data: { careStarterCode, careType, caredEmployeeCode, currentEmployeeCode }
    });
}

/**
 * 保存员工关怀信息
 * @param {object} param
 * @returns {Promise<any|{data: {data: *}}|{data: *}>}
 */
export async function saveEmployeeCare(param) {
    return request('/api/uc/employee/care/saveEmployeeCare', {
        method: 'POST',
        data: param
    });
}

/**
 * 编辑员工关怀
 * @param {string} param
 * @returns {Promise<any|{data: {data: *}}|{data: *}>}
 */
export async function updateEmployeeCare(param) {
    return request('/api/uc/employee/care/updateEmployeeCare', {
        method: 'POST',
        data: param
    });
}

/**
 * 获取招聘记录相关信息
 * @param {string} employeeCode
 * @returns {Promise<any|{data: {data: *}}|{data: *}>}
 */
export async function getRecruitmentInfo({ employeeCode }) {
    return request(`/api/oa/employee/manage/recruitment/record_info/${employeeCode}`, {
        method: 'GET'
    });
}

/**
 * 查询待入职员工数量
 */
export function queryEntryNumber() {
    return request('/api/entry/v1/process/queryEntryNumber', {
        method: 'GET'
    });
}

/**
 * 校验是否有目标用户访问权限
 */
export function checkHasEmployeePermission(employeeCode) {
    return request(`/api/uc/employee/manage/v1/checkHasEmployeePermission?employeeCode=${employeeCode}`, {
        method: 'GET'
    });
}

export function getWorkAgeList() {
    return Promise.resolve([
        {
            label: '不限',
            value: '[-]'
        },
        {
            label: '一年以内',
            value: '[-1]'
        },
        {
            label: '1-2年',
            value: '[1-2]'
        },
        {
            label: '2-3年',
            value: '[2-3]'
        },
        {
            label: '3-5年',
            value: '[3-5]'
        },
        {
            label: '5-7年',
            value: '[5-7]'
        },
        {
            label: '7-10年',
            value: '[7-10]'
        },
        {
            label: '10年以上',
            value: '[10-]'
        }
    ]);
}

export function getAgeList() {
    return Promise.resolve([
        {
            label: '不限',
            value: '[-]'
        },
        {
            label: '20以内',
            value: '[-20]'
        },
        {
            label: '21-25',
            value: '[21-25]'
        },
        {
            label: '26-30',
            value: '[26-30]'
        },
        {
            label: '31-35',
            value: '[31-35]'
        },
        {
            label: '36-40',
            value: '[36-40]'
        },
        {
            label: '41-50',
            value: '[41-50]'
        },
        {
            label: '51-60',
            value: '[51-60]'
        },
        {
            label: '60以上',
            value: '[60-]'
        }
    ]);
}

export function getSexList() {
    return Promise.resolve([
        {
            label: '不限',
            value: ''
        },
        {
            label: '男',
            value: '1'
        },
        {
            label: '女',
            value: '2'
        }
    ]);
}

/**
 * 获取员工的主管履历
 * @param {string} employeeCode 员工编码
 * @returns {Promise<any|{data: {data: *}}|{data: *}>}
 */
export async function getLeaderHistory(employeeCode) {
    return request(`/api/org/leaderSetting/v1/${employeeCode}/leaderHistory`, {
        method: 'GET'
    });
}

/**
 * 获取员工的主管履历
 * @param {object} params 主管数据
 * @returns {Promise<any|{data: {data: *}}|{data: *}>}
 */
export async function deleteLeader(params) {
    return request('/api/oa/leaderSetting/v1/leave/flow/submit', {
        method: 'POST',
        data: { ...params }
    });
}

/**
 * 获取工作任务
 * @param {string} employeeCode 员工编码
 * @returns {Promise<any|{data: {data: *}}|{data: *}>}
 */
export async function getTask(employeeCode) {
    // 目前这个功能还未开发
    return new Promise(resolve => {
        console.log('================>employeeCode', employeeCode);
        resolve(null);
    });
}

/**
 * 获取员工考勤记录
 * @param {string} employeeCode 员工编码
 * @returns {Promise<any|{data: {data: *}}|{data: *}>}
 */
export async function getAttendanceByEmployeeCode(employeeCode) {
    return request('/api/work/v1/attendance/attendancetoempcycle/employee/statistics', {
        method: 'POST',
        data: { employeeCode }
    });
}

/**
 * 获取主管概况-微微历程的聚合数据
 * @param {string} employeeCode 员工编码
 * @returns {Promise<any|{data: {data: *}}|{data: *}>}
 */
export function getGroupingOfCourseData(employeeCode) {
    return Promise.all([getLeaderHistory(employeeCode), queryEmployeeCourseList({ employeeCode })]).then(res => ({
        leaderHistoryData: res[0]?.code === 10000 ? res[0].data : null,
        courseData: res[1]?.code === 10000 ? res[1].data : null
    }));
}

/**
 * 获取主管概况-工作任务的聚合数据
 * @param {string} employeeCode 员工编码
 * @returns {Promise<any|{data: {data: *}}|{data: *}>}
 */
export function getGroupingOfTaskData(employeeCode) {
    return Promise.all([getTask(employeeCode)]).then(res => ({
        taskData: res[0]?.code === 10000 ? res[0].data : null
    }));
}

/**
 * 获取主管概况-考勤情况的聚合数据
 * @param {string} employeeCode 员工编码
 * @returns {Promise<any|{data: {data: *}}|{data: *}>}
 */
export function getGroupingOfAttendanceData(employeeCode) {
    return Promise.all([getAttendanceByEmployeeCode(employeeCode)]).then(res => ({
        attendanceData: res[0]?.code === 10000 ? res[0].data : null
    }));
}

/**
 * 查询员工基础信息和公司信息, 可通过employeeCode,userName，email查找
 * @param {string} employeeCode 员工编码
 * @param {string} userName 用户名
 * @param {string} email 邮箱
 * @returns {Promise<any|{data: {data: *}}|{data: *}>}
 */
export async function getEmployeeInfoAndAds({ employeeCode, userName, email }) {
    return request('/api/org/v1/employeeInfo/findEmployeeInfoAndAds', {
        method: 'POST',
        data: { employeeCode, userName, email }
    });
}

// 获取行政机构范围内动态属性
export function getEmployeeFieldConfig({ countryNameCode, groupCode }) {
    return request('/api/org/employeeFieldConfig/v1/getByCountryNameCodeAndGroupCode', {
        method: 'POST',
        data: { countryNameCode, groupCode }
    });
}
